<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:data="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<head th:include="include/include">
</head>
<style>
   /* body{font-size:12px;}
    td {
        border-width: 1px;
        border-top-style: solid;
        border-right-style: none;
        border-bottom-style: none;
        border-left-style: solid;
        text-align: center;
        width: 25%;
        height: 20px;
    }
    table {
        border-width:1px;
        border-right-style: solid;
        border-bottom-style: solid;
        border-top-style: none;
        border-left-style: none;
        border-color:#000;
    }*/
    /*.text { width: 95%;border: 1px dashed #FF9900; }*/
   /* .input{padding:0;margin:0;height:100%;width:100%;border:none;}*/

</style>
<script>
    // 将单元格转化成文本框
    function changeTotext(obj)
    {
        var tdValue = obj.innerText;
        obj.innerText = "";
        var txt = document.createElement("input");
        txt.type = "text";
        txt.value = tdValue;
        txt.id = "_text_000000000_";
       // txt.style="padding:0;margin:0;height:100%;width:100%;border:none;";

        txt.setAttribute("className","text");
        obj.appendChild(txt);
        txt.select();
        //obj.style.border = "1px dashed #ff9900";
    }
    // 取消单元格中的文本框，并将文本框中的值赋给单元格
    function cancel(obj)
    {
        var txtValue = document.getElementById("_text_000000000_").value;
        obj.innerText = txtValue;
    }
    /*********************************************/
    // 事件
    // document.onclick = function()
    // {
    //       var parentEls = $(event.srcElement).parents().map(function () {
    //        return this.tagName;
    //    }).get().join(", ");
    //    var arrayEls=parentEls.split(",");
    //    if(parentEls.indexOf("TABLE")>-1){
    //        var idTable= $(event.srcElement).parents("table").attr("id");
    //        if("partInfoTable"==idTable&&event.srcElement.tagName.toLowerCase() == "input"&&arrayEls[0]=="LABEL"){
    //            $(event.srcElement).blur(function(){
    //                var value=$(event.srcElement).val();
    //                if(value!=''){
    //                $(event.srcElement).attr('initvalue', function () { return this.value})
    //
    //                }
    //                //alert(value);
    //            })
    //
    //        }
    //    }
    // }

    document.onmouseup = function()
    {//点击放开后生效
       /* if (document.getElementById("_text_000000000_") && event.srcElement.id != "_text_000000000_")
        {
            var obj = document.getElementById("_text_000000000_").parentElement;
            cancel(obj);
        }*/
/*
        var parentEls = $(event.srcElement).parents().map(function () {
            return this.tagName;
        }).get().join(", ");
        var arrayEls=parentEls.split(",");
        if(parentEls.indexOf("TABLE")>-1){
            var idTable= $(event.srcElement).parents("table").attr("id");
            if("partInfoTable"==idTable&&event.srcElement.tagName.toLowerCase() == "input"&&arrayEls[0]=="LABEL"){
                var value=$(event.srcElement).val();
                alert(value);
            }
        }*/

    }





    //禁止滚动条
    $(document.body).css({
        "overflow-x":"hidden",
        "overflow-y":"auto"
    });
    $(function () {
        //保存
        $("#save").click(function(){
           var s= $("#threePartyVehicleDamageInfoForm").serialize();
           var method=$("#threePartyVehicleDamageInfoForm").attr("action");
            $.post("threePartyVehicleDamageInfo/updataByTaskNo",s,function(data){
                if(data.status==1){
                    alert(data.msg);

                }else{
                    alert(data.msg);
                }
            })

        });

        $('#scnf').datetimepicker({
            "format": 'yyyy-mm-dd'
            ,"language":"zh-CN",
            weekStart: 1, //一周从哪一天开始
            todayBtn:  "linked",
            autoclose: 1,
            todayHighlight: 1,
            startView: 4,
            forceParse: 0,
            showMeridian: 1
            // ,"startDate":"2018-01-01"
            ,initialDate: new Date()
        });

        /*$(":input").click(function(){
             //return this.getAttribute('initvalue');
            alert("sss");
        });*/
        //配件信息小计-定损
        $(".calculateSum").blur(function(){//小计
          var sum=eachTable("partInfoTable",5);
           var canzhi= $(this).parent().parent().prev().children().eq(0).children(":input").val();
            var managerFee= $(this).parent().parent().next().children().eq(0).children(":input").val();
            if(!isNaN(canzhi)){
                sum=Number(sum)-Number(canzhi);
            }
            if(!isNaN(managerFee)){
                sum=Number(sum)-Number(managerFee);
            }
            $(this).val(sum.toFixed(2));
        });
        //配件信息小计-核价
        $("#calculateSum1").blur(function(){//小计
            var sum=eachTable("partInfoTable",6);
            var canzhi= $(this).parent().parent().prev().children().eq(1).children(":input").val();
            var managerFee= $(this).parent().parent().next().children().eq(1).children(":input").val();
            if(!isNaN(canzhi)){
                sum=Number(sum)-Number(canzhi);
            }
            if(!isNaN(managerFee)){
                sum=Number(sum)-Number(managerFee);
            }
            $(this).val(sum.toFixed(2));
        });
        $("#calculateSumManHour1").blur(function(){
            var sum=eachTable("manHourTable",2);
            //alert(sum);
           $(this).val(sum);
        });
        $("#calculateSumManHour2").blur(function(){
            var sum=eachTable("manHourTable",3);
            $(this).val(sum);
        });

        $("#calculateSumFee1").blur(function(){
            var sum=eachTable("feeTable",2);
            $(this).val(sum);
        });
        $("#calculateSumFee2").blur(function(){
            var sum=eachTable("feeTable",3);
            $(this).val(sum);
        });
    });

    //计算合计值
    //id dom对象的 id
    // index 指定列
    function eachTable(id,indexs){
        var sum=0;
        $("#"+id+" tbody tr").each(function(index){
            var obj=$(this).children().eq(0).children();
            var objName=obj.get(0).tagName.toLowerCase();

            if(objName!='button'){
                var objValue=$(this).children().eq(indexs).children().children().val();
                if(!isNaN(objValue)){
                    sum+=parseFloat(objValue)
                }
            }else if(objName=='button'){
                //$(".calculateSum").val(sum.toFixed(2));
                return false;
            }
        });

        return sum.toFixed(2);

    }

    //供父页面调用的子页面
    /*taskNo->三者信息的任务编号 taskId->任务id */
    function getParentData2(taskNo,taskId){

        if(taskNo!=''){
            $("#taskNo").val(taskNo);
            $.post("threePartyVehicleDamageInfo/findByTaskNo",{taskNo:taskNo},function(data){
                if(data.status==1){
                    var xlcmc=data.data.xlcmc;//修理厂名称
                    $("#xlcmc").val(xlcmc);//
                    var xylcqk=data.data.xylcqk;//选修理厂情况
                    $("#xylcqk option[value='"+xylcqk+"']").prop("selected",true);
                    var xlclx=data.data.xlclx;//修理厂类型
                    $("#xlclx option[value='"+xlclx+"']").prop("selected",true);
                    var cph=data.data.cph;//车牌号
                    $("#cph").val(cph);
                    var bbxr=data.data.bbxr;//被保险人
                    $("#bbxr").val(bbxr);
                    var xszcz=data.data.xszcz;//行驶证车主
                    $("#xszcz").val(xszcz);
                    var hplx=data.data.hplx;
                    $("#hplx option[value='"+hplx+"']").prop("selected",true);
                    var cjh=data.data.cjh;//车架号
                    $("#cjh").val(cjh);
                    var fdjh=data.data.fdjh;//发动机号
                    $("#cjh").val(fdjh);
                    var jsyxm=data.data.jsyxm;//驾驶员姓名
                    $("#jsyxm").val(jsyxm);
                    var zjhm=data.data.zjhm;//证件号码
                    $("#zjhm").val(zjhm);
                    var zjcx=data.data.zjcx;//准驾车型
                    $("#zjcx option[value='"+zjcx+"']").prop("selected",true);
                    var jsyxb=data.data.jsyxb;//驾驶员性别
                    $("#jsyxb option[value='"+jsyxb+"']").prop("selected",true);
                    var sccj=data.data.sccj;//生产厂家
                    $("#sccj").val(sccj);
                    var clpp=data.data.clpp;//车辆品牌
                    $("#clpp").val(clpp);
                    var cxll=data.data.cxll;//车型系列
                    $("#cxll").val(cxll);
                    var clxh=data.data.clxh;//车型型号
                    $("#clxh").val(clxh);
                    var scnf=data.data.scnf;//生产年份
                    $("#scnf").val(scnf);

                    var csdjhj=data.data.csdjhj;//车损定损合计
                    $("#csdjhj").val(csdjhj);
                    var dsxz=data.data.dsxz;//定损险种
                    $("#dsxz option[value='"+dsxz+"']").prop("selected",true);
                    var zzdfjqxpf=data.data.zzdfjqxpf;//责任对方交强险赔付
                    $("#zzdfjqxpf").val(zzdfjqxpf);
                    var cshjhj=data.data.cshjhj;//车损核价合计
                    $("#cshjhj").val(cshjhj);
                    var jqxbdh=data.data.jqxbdh;//交强险保单号或凭证号
                    $("#jqxbdh").val(jqxbdh);
                    var cbgs=data.data.cbgs;//承保公司
                    $("#cbgs").val(cbgs);
                    var xxscjg=data.data.xxscjg;//现行市场价格
                    $("#xxscjg").val(xxscjg);
                    var  sgzr=data.data.sgzr;//责任事故
                    $("#sgzr option[value='"+sgzr+"']").prop("selected",true);
                    var  sgzebfb=data.data.sgzebfb;//责任事故百分比
                    $("#sgzebfb option[value='"+sgzebfb+"']").prop("selected",true);
                    var  dssm=data.data.dssm;//定损说明
                    $("#dssm").val(dssm);
                }else{
                    alert(data.msg);
                }


            })
            partInfo(taskNo);//配件信息
            manHourInfo(taskNo);//工时费信息
            costInfo(taskNo);//费用信息

        }

    }
    //测试添加输入框
    function text1(val){
        var h=$(val).parent().outerHeight()-1;
        var w=$(val).parent().outerWidth()-1;
        var value=$(val).text();
        $(val).parent().css("padding","0px");
        $(val).parent().append("<input value='"+value+"' style='width:"+w+"px;height:"+h+"px;border:1px solid red;padding:0px;'/>");
        $(val).remove();
    }
    //删除当前行
    function deletetr(tr,ids,url,type){
        if(ids!=''&&ids!=null&& typeof ids!="undefined"){
            BootstrapDialog.show({
                title: '确认删除',
                message: '是否删除？',
                type:BootstrapDialog.TYPE_WARNING,
                size:BootstrapDialog.SIZE_SMALL,
                buttons: [{
                    label: '确认',
                    action: function(dialog) {
                        $.ajax({
                            url:url,
                            data:{id:ids},
                            dataType:"JSON",
                            type:type,
                            async:false,
                            success:function(data){
                                if(data!=null){
                                    if(data.status==1){
                                        dialog.close();
                                        $(tr).parent().parent().remove();
                                    }
                                }
                            },
                            error:function(){

                            }
                        })


                    }
                }, {
                    label: '取消',
                    action: function(dialog) {
                        dialog.close();
                    }
                }]
            });

        }

    }

    /**
     * 查询工时信息
     * @constructor
     */
    function manHourInfo(taskNo){
        if(taskNo!=''&&typeof taskNo!="undefined"){
            $.ajax({
                url:'assessmentLossCheckPriceDetail/list',
                data:{limit: 50, // 每页要显示的数据条数
                    offset: 0, // 每页显示数据的开始行号
                    page: 1,
                    renwuhao:taskNo,
                },
                dataType:"JSON",
                type:"POST",
                success:function (data) {
                    if(data!=null){
                        $.each(data.rows,function(index,item){
                           var str=addmanHourItems(item.xzmc,item.xlxm,item.gsbj,item.gsfhs,item.zhuangtai,item.ids)
                            $("#manHourAdd").before(str);
                        })
                    }else{
                        alert("查询异常");

                    }


                },
                error:function () {
                }
            });

        }

    }

//查询配件信息
    function  partInfo(taskNo){
        if(taskNo!=''){
            $.get("fixedLossCheckPriceDetail/findPageByTaskNum",{
                limit: 50, // 每页要显示的数据条数
                offset: 0, // 每页显示数据的开始行号
                page: 1,
                renwubianhao:taskNo,
            },function(data){
                if(data!=null){
                    var datas=data.rows;
                    if(datas!=null){
                        $.each(datas,function(index,item){
                            addParts1(item.xzmc,item.pjmc,item.bdjg,item.xtjg,item.sl,item.dsj,item.hj,item.jgan,item.sfhs,item.zhuangtai,item.ids,item.renwubianhao);
                        });
                    }
                }

            })

        }

    }
   // $('tbody td label >input').attr('initvalue', function () { return this.value});
   // $('#dv input').val(function () { return this.getAttribute('initvalue')})
    //更新配件信息
    function update1(val,ids,name){
        if(ids!=''&&name!=''){
            var map={};

            if (typeof val=="boolean" ) {
                if(val){
                    map[name]=1;
                }else{
                    map[name]=0;
                }
            }else if(typeof val=="object"){
                var tdValue=$(val).val();
                console.log("旧值:"+val.defaultValue+"新值："+tdValue);
                if(tdValue==''||val.defaultValue==tdValue){//为空或者未改变值
                    return;
                }
                if(name=='hj'){//修改状态值
                    var dsj=$(val).parent().parent().prev().children().children(":input").val();//定损价值
                    var statusObj=  $(val).parent().parent().parent().children().eq(9).children();//获取状态栏信息
                    if(dsj==tdValue&&tdValue!="0.00"&&tdValue!="0"){
                      var statusVal= statusObj.text();//状态值
                        //console.log("状态："+statusVal);
                        if(statusVal!="已完成"&&statusVal!="完成"){
                            map['zhuangtai']=1;
                            statusObj.text("已完成");
                        }
                    }else{
                        if(statusVal!="未完成"){
                            map['zhuangtai']=0;
                            statusObj.text("未完成");
                        }

                    }
                }
                map[name]=tdValue;
            }
            map['ids']=ids;
            $.ajax({
                url:'fixedLossCheckPriceDetail/update',
                data:map,
                dataType:'JSON',
                type:'POST',
                async:false,
                success:function(data){
                    console.log(data.status);
                    if(data.status==1){
                        //console.log("更新的值"+map[name])
                        val.defaultValue=map[name];
                       /* saveData(index, field, tdValue)*/;
                      /* if(name=='hj'){
                           var dsj=$(val).parent().parent().prev().children().children(":input").val();
                           if(dsj==map[name]&&dsj!="0.00"&&dsj!="0"){


                           }
                       }*/
                    }else{
                        BootstrapDialog.show({
                            title: '提示信息',
                            message: data.msg,
                            type: BootstrapDialog.TYPE_WARNING,
                            size: BootstrapDialog.SIZE_SMALL,
                            buttons: [{
                                label: '确认',
                                action: function (dialog) {
                                    dialog.close();
                                }
                            }]
                        });
                        $(val).val("");

                    }

                },
                error:function(){

                }


            })

            console.log(ids+'==='+name);

        }
    }
    // function upd(e){
    //     e.value=e.defaultValue;//取消时还原
    // }
    function updateIsRecycling(e,ids,name){//更新是否回收
        var ischecked = $(e).prop("checked");
        update1(ischecked,ids,name);
    }

    //添加配件行信息
    function  addParts1(xzmc,pjmc,bdjg,xtjg,sl,dsj,hj,jgan,sfhs,zhuangtai,ids,taskNo){
        var str="<tr class='text-center'>"+
            "<td>" +
                "<label>"+
                    "<select name='' readonly>" +
                        "<option value='"+xzmc+"'>"+xzmc+"</option>"+
                    "</select>"+
                "</label>"+
            "</td> " +
            "<td >" +
                "<label><input value='"+pjmc+"'class='width80' onblur=\"update1(this,'"+ids+"','pjmc')\"/> " +
                "<span class='glyphicon glyphicon-pencil'></span></label> " +
            "</td>" +
            "<td>" +
                "<label ><input value='"+bdjg+"' class='width80'  onblur=\"update1(this,'"+ids+"','bdjg')\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>" +
            "</td>"+
            "<td >"+
                "<label ><input value='"+xtjg +"' class='width80' onblur=\"update1(this,'"+ids+"','xtjg')\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"></label>"+
            "</td>" +
            "<td >" +
                "<label ><input value='"+sl+"' class='width80' onblur=\"update1(this,'"+ids+"','sl')\" onkeyup=\"value=value.replace(/^(0+)|[^\\d]+/g,'')\" type='number'min='1'/></label>" +
            "</td>" +
            "<td>" +
                "<label ><input value='"+dsj+"' class='width80' onblur=\"update1(this,'"+ids+"','dsj')\"  onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>" +
            "</td>" +
            "<td>" +
                "<label ><input value='"+hj+"' class='width80' onblur=\"update1(this,'"+ids+"','hj')\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>"+
            "</td>" +
            "<td>" +
                "<label><select name='jgan'value='' readonly>" +
                    "<option value='"+jgan+"'>"+jgan+"</option>"+
                "</select></label>"+
            "</td>" +
            "<td class='width80'>" +
                "<label class='checkbox'>" +
                    "<input type='checkbox' name='' value='1' name='sfhs'";
                if(sfhs==1){
                    str+=" checked";
                }
                    str+= " onchange=\"updateIsRecycling(this,'"+ids+"','sfhs');\"/>" +
                "</label>" +
            "</td>" +
            "<td >";
                if(zhuangtai==1){
                    zhuangtai="已完成";
                }else if(zhuangtai==0){
                    zhuangtai="未完成";
                }
                str+="<label > "+zhuangtai+"</label>"+
            "</td>" +
            "<td>" +
                    "<span class='glyphicon glyphicon-remove-sign' onclick=\"deletetr(this,"+ids+",'fixedLossCheckPriceDetail/deleteById','GET');\"></span>" +
/*
                    " <span class='glyphicon glyphicon-pencil' onclick='updatetr(this,"+ids+")'></span><span style='display: none;'>"+ids+"</span><span style='display: none;'>"+taskNo+"</span>" +
*/
                    "</td>" +
            "</tr>";
        $("#tr_addParts").before(str);

    }
    //添加配件方法
    function addParts(val){
       //alert( (typeof  $("#tr_addParts").prev().get(0)) != "undefined");
        /*判断是否存在数据信息*/
        var taskNo= $("#taskNo").val();
        if(taskNo==''){
            alert("未获取任务编号");
            return;
        }
        var xlclx=$("#xlclx").val();
        if(xlclx=="0"){
            BootstrapDialog.show({
                title: '确认选择了修理厂类型',
                message: '请选择修理厂类型',
                type:BootstrapDialog.TYPE_WARNING,
                size:BootstrapDialog.SIZE_SMALL,
                buttons: [{
                    label: '确认',
                    action: function(dialog) {
                        dialog.close();
                    }
                }, {
                    label: '取消',
                    action: function(dialog) {
                        dialog.close();
                    }
                }]
            });
        }else{
           var xlclxText= $("#xlclx").find("option:selected").text();//修理厂类型
            var dataArry=new Array();
            if((typeof $(val).parent().parent().prev().get(0)) != "undefined"){//存在
                var rowdata= $(val).parent().parent().prev().find(">td");

                rowdata.each(function(index,item){
                    if(index==0||index==7 ){
                        var  s= $(this).children("label").children("select").val();
                        dataArry.push(s);
                    }else if( index>=1&&index<=6){
                        dataArry.push($(this).children("label").children("input").val());
                    }else if(index==8){
                        var checkedBox=$(this).children("label").children(":checkbox");
                        if(checkedBox.is(':checked')) {
                            dataArry.push(1);
                        }else{
                            dataArry.push(0);
                        }
                    }

                });
            }else{//不存在
                dataArry=['第三方责任险','',0.00,0.00,0,0.00,0.00,xlclxText,0];
            }
            var map={xzmc:dataArry[0],pjmc:dataArry[1],bdjg:dataArry[2],xtjg:dataArry[3],sl:dataArry[4],dsj:dataArry[5],hj:dataArry[6],jgan:dataArry[7],sfhs:dataArry[8],renwubianhao:taskNo};
            $.ajax({
                url: "fixedLossCheckPriceDetail/add",
                data: map,
                dataType: "JSON",
                type: "POST",
                async: false,
                success: function (data) {
                    //console.log(data.data.ids);
                    if (data.status==1) {
                        var addDatas=data.data;
                        addParts1(addDatas.xzmc,addDatas.pjmc,addDatas.bdjg,addDatas.xtjg,addDatas.sl,addDatas.dsj,addDatas.hj,addDatas.jgan,addDatas.sfhs,addDatas.zhuangtai,addDatas.ids,addDatas.renwubianhao);
                    } else {
                        alert("添加失败");
                    }

                }
            })

        }
    }
    //查询费用信息
    function costInfo(taskNo){
        if(taskNo!=''){
            $.post("manHour/list",{limit: 50, // 每页要显示的数据条数
                offset: 0, // 每页显示数据的开始行号
                page: 1,
                renwuno:taskNo,},function(data){
                if(data!=null){
                    $.each(data.rows,function(index,item){
                        var str=addCostTrInfo(item.dsxz,item.fylx,item.fyje,item.hsje,item.sm,item.ids);
                        $("#tr_addCost").before(str);
                    })

                }


            })
        }
    }
    //添加费用信息行
    function addCostTrInfo(dsxz,fylx,fyje,hsje,sm,ids){
        if(fylx==null){
            fylx="-请选择-";
        }
        var str="<tr class='text-center'>  " +
            "                                        <td>  " +
            "                                            <label>  " +
            "                                                <select>  " +
            "                                                    <option value='"+dsxz+"'>"+dsxz+"</option>  " +
            "                                                </select>  " +
            "                                            </label>  " +
            "                                        </td>  " +
            "                                        <td>  " +
            "                                            <label>  " +
            "                                                <select>  " +
            "                                                    <option value='"+fylx+"'>"+fylx+"</option>  " +
            "                                                </select>  " +
            "                                            </label>  " +
            "                                        </td>  " +
            "                                        <td>  " +
            "                                            <label><input value='"+fyje+"' onblur=\"updateFee(this,"+ids+",'fyje');\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>" +
            "                                        </td>  " +
            "                                        <td>  " +
            "                                            <label><input value='"+hsje+"' onblur=\"updateFee(this,"+ids+",'hsje');\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>  " +
            "                                        </td>  " +
            "                                        <td> " +
            "                                            <label><input value='"+sm+"' onblur=\"updateFee(this,"+ids+",'sm');\"/></label>" +
            "                                       </td> " +
            "                                       <td> " +
            "                                           <span class='glyphicon glyphicon-remove-sign ' onclick=\"deletetr(this,"+ids+",'manHour/delById','GET');\"></span>" +
            "                                       </td>" +
            "   </tr>";
        return str;

    }
    function updateFee(val,ids,name){
        if(ids!=''&&name!=''){

            var map={};

            if (typeof val=="boolean" ) {
                if(val){
                    map[name]=1;
                }else{
                    map[name]=0;
                }
            }else if(typeof val=="object"){
                var tdValue=$(val).val();
                console.log("旧值:"+val.defaultValue+"新值："+tdValue);
                if(tdValue==''||val.defaultValue==tdValue){//为空或者未改变值
                    return;
                }
                map[name]=tdValue;
            }
            map['ids']=ids;
            $.ajax({
                url: 'manHour/update',
                data: map,
                dataType: 'JSON',
                type: 'POST',
                async: false,
                success: function (data) {
                    console.log(data.status);
                    if (data.status == 1) {
                        //saveData(index, field, tdValue);
                        //$table.bootstrapTable('updateRow', {index: row.rowId, row: row});
                    } else {
                        BootstrapDialog.show({
                            title: '提示信息',
                            message: data.msg,
                            type: BootstrapDialog.TYPE_WARNING,
                            size: BootstrapDialog.SIZE_SMALL,
                            buttons: [{
                                label: '确认',
                                action: function (dialog) {
                                    dialog.close();
                                }
                            }]
                        });

                    }

                },
                error: function () {

                }


            })

        }
    }
    //    添加费用
    function addCost(val){
        var taskNo=$("#taskNo").val();
        var map={'dsxz':'第三方责任险',renwuno:taskNo};
        $.ajax({
            url: "manHour/add",
            data: map,
            dataType: "JSON",
            type: "POST",
            async: false,
            success: function (data) {
                if (data.status==1) {
                    var datas=data.data;
                  var str=  addCostTrInfo(datas.dsxz,datas.fylx,datas.fyje,datas.hsje,datas.sm,datas.ids);
                    $("#tr_addCost").before(str);
                } else {
                    alert("添加失败");
                }

            }
        })

    }
    //添加工时行信息
    function addmanHourItems(xzmc,xlxm,gsbj,gsfhs,zhuangtai,ids){
        if(xzmc==""){
            xzmc="第三方责任险";
        }
        if(xlxm==null){
            xlxm="";
        }
        if(zhuangtai=="0"){
            zhuangtai="未完成";
        }else if(zhuangtai=="1"){
            zhuangtai="已完成";
        }
        var str="<tr class='text-center'>" +
            "       <td>" +
            "           <label>" +
            "               <select>" +
            "                   <option value='"+xzmc+"'>"+xzmc+"</option>" +
            "               </select>" +
            "           </label>" +
            "       </td>" +
            "       <td>" +
            "           <label>" +
            "               <input value='"+xlxm+"' name='' class='width80' onblur=\"updateManHour(this,"+ids+",'xlxm');\"/>" +
            "           </label>" +
            "       </td>" +
            "       <td>" +
            "           <label>" +
            "               <input value='"+gsbj+"' name='' class='width80' onblur=\"updateManHour(this,"+ids+",'gsbj');\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/>" +
            "           </label>" +
            "       </td>" +
            "       <td>" +
            "           <label><input value='"+gsfhs+"' name='' class='width80' onblur=\"updateManHour(this,"+ids+",'gsfhs');\" onkeyup= \"if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value=this.defaultValue;}\"/></label>" +
            "       </td>" +
            "       <td><label>"+zhuangtai+"</label>" +
            "       </td>" +
            "       <td style='text-align: center'>" +
            "           <span class='glyphicon glyphicon-remove-sign ' onclick=\"deletetr(this,"+ids+",'assessmentLossCheckPriceDetail/delById','GET');\"></span>" +
            // "           <span class='glyphicon glyphicon-pencil margin5Left' ></span>" +
            "       </td>" +
            "   </tr>";
                return str;

    }
//    添加工时信息
    function addItems(val) {
        var taskNo= $("#taskNo").val();
        var map={xzmc:'第三方责任险',renwuhao:taskNo};
        if(taskNo!=''){
            $.ajax({
                url: "assessmentLossCheckPriceDetail/add",
                data: map,
                dataType: "JSON",
                type: "POST",
                async: false,
                success: function (data) {
                    if (data.status==1) {
                        var datas=data.data;
                        var str= addmanHourItems(datas.xzmc,datas.xlxm,datas.gsbj,datas.gsfhs,datas.zhuangtai,datas.ids);
                        $(val).parent().parent().before(str);
                    } else {
                        alert(data.msg);
                    }

                }
            })




        }else{
            alert("未获取任务号");
        }



    }

    /**
     * 更新工时信息
     * @param val 更新项
     * @param ids 更新项的id
     * @param name 更新项的名称
     */
    function updateManHour(val,ids,name){
        if(ids!=''&&ids!=null&&typeof  ids !="undefined"&&name!=''){
            var map=new Map();
            if (typeof val=="boolean" ) {
                if(val){
                    map[name]=1;
                }else{
                    map[name]=0;
                }
            }else if(typeof val=="object"){
                var tdValue=$(val).val();
                console.log("旧值:"+val.defaultValue+"新值："+tdValue);
                if(tdValue==''||val.defaultValue==tdValue){//为空或者未改变值
                    return;
                }
                if(name=='gsfhs'){//修改状态值
                    var gsbj=$(val).parent().parent().prev().children().children(":input").val();//工时报价
                    var statusObj=  $(val).parent().parent().parent().children().eq(4).children();//获取状态栏信息
                    if(gsbj==tdValue&&tdValue!="0.00"&&tdValue!="0"){
                        var statusVal= statusObj.text();//状态值
                        //console.log("状态："+statusVal);
                        if(statusVal!="已完成"&&statusVal!="完成"){
                            map['zhuangtai']=1;
                            statusObj.text("已完成");
                        }
                    }else{
                        if(statusVal!="未完成"){
                            map['zhuangtai']=0;
                            statusObj.text("未完成");
                        }

                    }
                }
                map[name]=tdValue;
            }
            map['ids']=ids;
            $.ajax({
                url: 'assessmentLossCheckPriceDetail/update',
                data: map,
                dataType: 'JSON',
                type: 'POST',
                async: false,
                success: function (data) {
                    console.log(data.status);
                    if (data.status == 1) {

                    } else {
                        BootstrapDialog.show({
                            title: '提示信息',
                            message: data.msg,
                            type: BootstrapDialog.TYPE_WARNING,
                            size: BootstrapDialog.SIZE_SMALL,
                            buttons: [{
                                label: '确认',
                                action: function (dialog) {
                                    dialog.close();
                                }
                            }]
                        });

                    }

                },
                error: function () {

                }


            })

        }

    }






</script>
<body>
<div class="container-fluid">
    <div id="form">
        <form class="form-inline" role="form" action="threePartyVehicleDamageInfo/update" method="post" id="threePartyVehicleDamageInfoForm">
            <!--定损信息开始-->
            <div class="row">
                <div class="col-md-12 " id="leftRightAlignment">
                    <table class="table table-condensed table-bordered">
                        <tbody>
                            <tr style="display: none;">
                                <td > <input value="" id="taskNo" name="renwuno"/></td>
                            </tr>
                            <tr>
                                <td><label>修理厂名称：</label></td>
                                <td colspan="2"><label class="form-group"><input name="xlcmc" class="form-control" id="xlcmc"/></label> <button type="button" class="btn-info btn-sm">查询修理厂</button></td>
                               <td>
                                    <label >选修理厂情况:</label>
                                </td>
                                <td colspan="2">
                                    <label>
                                        <select name="xylcqk" id="xylcqk">
                                            <option value="0">-请选择-</option>
                                            <option value="1"> 综合型修理厂</option>
                                            <option value="2"> 特色型修理厂</option>
                                            <option value="3"> 专项型修理厂</option>
                                        </select>
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <td><label>是否推送修：</label></td>
                                <td >
                                    <label class="form-group">
                                        <input name="sftsx" type="radio"  value="1"/>是
                                        <input name="sftsx" type="radio"  value="0"/>否
                                        <input name="sftsx" type="radio"  value="2"/>改送
                                    </label>
                                </td>
                                <td><label>未推送修备注：</label></td>
                                <td><label class="form-group">
                                    <select name="wtsxbz"  id="wtsxbz" style="height:21px;">
                                        <option value="0">-请选择-</option>
                                        <option value="1">距离太远</option>
                                        <option value="2">回承保修理厂修理</option>
                                        <option value="3">客户不信任</option>
                                        <option value="4">已有其他修理厂介入</option>
                                        <option value="5">其他原因</option>
                                    </select></label>
                                </td>
                                <td>
                                    <label class="text-right">组织结构代码:</label>
                                </td>
                                <td>
                                    <label> <input class="" value="" name=""/></label>
                                </td>
                            </tr>
                            <tr>
                                <td><label>修理厂类型:</label></td>
                                <td colspan="3">
                                    <label>
                                        <select name="xlclx" id="xlclx">
                                            <option value="0">-请选择-</option>
                                            <option value="1">一类修理厂</option>
                                            <option value="2">二类修理厂</option>
                                            <option value="3">三类修理厂</option>
                                            <option value="4">4S店</option>
                                        </select>
                                    </label>
                                </td>
                                <td>
                                    <label>车牌号:</label>
                                </td>
                                <td ><label><input value="" name="cph" id="cph"/></label></td>
                            </tr>
                            <tr>
                                <td><label>被保险人:</label></td>
                                <td><label><input value="" name="bbxr" id="bbxr"/></label></td>
                                <td><label>行驶证车主:</label></td>
                                <td><label><input value="" name="xszcz" id="xszcz"/></label></td>
                                <td><label>品牌种类:</label></td>
                                <td>
                                    <label>
                                        <select name="hplx" id="hplx">
                                            <option value="0">-请选择-</option>
                                            <option value="1">01-大型汽车号牌</option>
                                            <option value="2">02-中型汽车号牌</option>
                                            <option value="3">03-小型汽车号牌</option>
                                            <option value="4">04-使馆汽车号牌</option>
                                            <option value="5">05--领馆汽车号牌</option>
                                            <option value="6">06-境外汽车号牌</option>
                                            <option value="7">07-外籍汽车号牌</option>
                                            <option value="8">08-两、三轮摩托车号牌</option>
                                            <option value="9">09-轻便摩托车号牌</option>
                                            <option value="10">10-使馆摩托车号牌</option>
                                            <option value="11">11-领馆摩托车号牌</option>
                                            <option value="12">12-境外摩托车号牌</option>
                                            <option value="13">13-外籍摩托车号牌</option>
                                            <option value="14">14-农用运输车号牌</option>
                                            <option value="15">15-拖拉机号牌</option>
                                            <option value="16">16-挂车号牌</option>
                                            <option value="17">17-教练汽车号牌</option>
                                            <option value="18">18-教练摩托车号牌</option>
                                            <option value="19">19-试验汽车号牌</option>
                                            <option value="20">20-试验摩托车号牌</option>
                                            <option value="21">21-临时入境汽车号牌</option>
                                            <option value="22">22-临时入境摩托车号牌</option>
                                            <option value="23">23-临时行驶车号牌</option>
                                            <option value="24">24-公安警车号牌</option>
                                            <option value="25">25-其他车型</option>
                                            <option value="26">26-专用机械</option>
                                            <option value="27">27-警备摩托车</option>
                                            <option value="28">28-大型警车</option>
                                            <option value="29">29-燃油助力车</option>
                                            <option value="30">30-电驱动二轮车</option>
                                            <option value="31">31-二轮摩托车</option>
                                            <option value="32">32-正三轮摩托车</option>
                                            <option value="33">33-侧三轮摩托车</option>
                                            <option value="34">34-残疾人机动轮椅车</option>
                                            <option value="35">35-电驱动三轮车</option>
                                            <option value="36">36-武警号牌</option>
                                            <option value="37">37-军队号牌</option>
                                            <option value="38">38-无号牌</option>
                                            <option value="39">39-假号牌</option>
                                            <option value="40">40-挪用号牌</option>
                                            <option value="41">41-其他号牌</option>
                                            <option value="42">42-大型能源汽车</option>
                                            <option value="43">43-小型能源汽车</option>
                                        </select>
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <td><label>车架号:</label></td>
                                <td><label><input value="" name="cjh" id="cjh"/></label></td>
                                <td><label>发动机号:</label></td>
                                <td><label><input value="" name="fdjh" id="fdjh"/></label></td>
                                <td><label>驾驶员姓名:</label></td>
                                <td><label><input value="" name="jsyxm" id="jsyxm"/></label></td>
                            </tr>
                            <tr>
                                <td><label>证件号码:</label></td>
                                <td><label><input value="" name="zjhm" id="zjhm"/></label><button type="button" class="btn-mini margin5Left" >历史赔付信息</button></td>
                                <td><label>准驾车型:</label></td>
                                <td><label><select name="zjcx" id="zjcx">
                                    <option value="0">-请选择-</option>
                                    <option value="1">A1(大型客车)</option>
                                    <option value="2">A2(牵引车)</option>
                                    <option value="3">A3(城市公交车)</option>
                                    <option value="4">B1(中型客车)</option>
                                    <option value="5">B2(大型客车)</option>
                                    <option value="6">C1(小型汽车)</option>
                                    <option value="7">C2(小型自动挡汽车)</option>
                                    <option value="8">C3(低速载货汽车)</option>
                                    <option value="9">C4(三轮汽车)</option>
                                    <option value="10">D(普通三轮摩托车)</option>
                                    <option value="11">E(普通二轮摩托车)</option>
                                    <option value="12">F(轻便摩托车)</option>
                                    <option value="13">M(轮式自行机械车)</option>
                                    <option value="14">N(无轨电车)</option>
                                    <option value="15">P(有轨电车)</option>
                                </select></label></td>
                                <td><label>驾驶员性别:</label></td>
                                <td><label><select name="jsyxb" id="jsyxb"><option value="1">男</option><option value="0">女</option></select></label></td>
                            </tr>
                            <tr>
                                <td><label>生产厂家:</label></td>
                                <td><label><input value="" name="sccj" id="sccj"/></label></td>
                                <td><label>车辆品牌:</label></td>
                                <td><label><input value="" name="clpp" id="clpp"/></label></td>
                                <td><label>车型系列:</label></td>
                                <td><label><input value="" name="cxll" id="cxll"/></label></td>
                            </tr>
                            <tr>
                                <td><label>车辆型号:</label></td>
                                <td><label><input value="" name="clxh" id="clxh"/></label></td>
                                <td><label>生产年份:</label></td>
                                <td><label><input value="" name="scnf" id="scnf"/></label></td>
                                <td><label>车损定损合计:</label></td>
                                <td><label><input value="" name="csdjhj" id="csdjhj" onkeyup= "if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value='';}"/></label></td>
                            </tr>
                            <tr>
                                <td><label>定损险种:</label></td>
                                <td><label><select name="dsxz" id="dsxz"><option value="">第三者责任保险</option></select></label></td>
                                <td><label>责任对方交强险赔付:</label></td>
                                <td><label><input value="" name="zzdfjqxpf" id="zzdfjqxpf" onkeyup= "if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value='';}"/></label></td>
                                <td><label>车损核价合计:</label></td>
                                <td><label><input value="" name="cshjhj" id="cshjhj" onkeyup= "if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value='';}"/></label></td>
                            </tr>
                            <tr>
                                <td><label>交强险保单号或凭证号:</label></td>
                                <td><label><input name="jqxbdh" value="" id="jqxbdh"/></label></td>
                                <td><label>承保公司:</label></td>
                                <td colspan="3"><label><input value="" name="cbgs" id="cbgs"/></label></td>
                            </tr>
                            <tr>
                                <td><label>现行市场价格:</label></td>
                                <td><label><input value="" name="xxscjg" id="xxscjg" onkeyup= "if(! /^[0-9]{1,}(?:.[0-9]{0,2})?$/.test(this.value)){alert('只能输入数字,小数点后只能保留两位');this.value='';}"> </label></td>
                                <td><label>事故责任:</label></td>
                                <td colspan="3">
                                    <label>
                                        <select name="sgzr" id="sgzr">
                                            <option value="100">全责</option>
                                            <option value="80">主责</option>
                                            <option value="50">同责</option>
                                            <option value="30">次责</option>
                                            <option value="0">无责</option>
                                        </select>
                                    </label>
                                    <label class="margin5Left">
                                        <select name="sgzebfb" id="sgzebfb">
                                            <option value="100">100</option>
                                            <option value="80">80</option>
                                            <option value="50">50</option>
                                            <option value="30">30</option>
                                            <option value="0">0</option>
                                        </select>%
                                    </label>
                                </td>
                            </tr>
                        </tbody>
                    </table>

                </div>

            </div>
            <!--定损信息结束-->
            <!--计算折旧价格开始-->
            <div class="row">
                <div class="col-md-12">
                    <div class="modelTitle text-center">
                        <label>计算折旧价格</label>
                    </div>
                    <table class="table table-condensed border0table">
                        <tbody>
                            <tr>
                                <td><label>新车购置价格:</label><label><input value="" name=""/></label></td>
                                <td><label>车辆种类:</label><label><select name=""><option value="">9座(含9座)以下非营运载客汽车(包括轿车含越野型)</option></select></label></td>
                                <td><label>折旧率:<input value="" name=""/></label></td>
                            </tr>
                            <tr>
                                <td><label>出险时间:</label><label><input value="" name=""/></label></td>
                                <td><label>初登日期:</label><label><input name="" value=""/></label></td>
                                <td><label>计算公式:<input value="" name=""/><button type="button" class="btn-mini">计算</button></label></td>
                            </tr>
                        </tbody>

                    </table>
                </div>

            </div>
            <!--计算折旧价格结束-->
            <!--配件信息-->
            <div class="row">
                <div class="col-md-12">
                    <div class="modelTitle text-center">
                        <label>配件信息</label>
                    </div>
                    <table class="table table-condensed table-bordered" id="partInfoTable">
                        <thead>
                        <tr class="tableTheadcolor">
                            <th>险种名称</th>
                            <th>配件名称</th>
                            <th>本地价格</th>
                            <th>系统价格</th>
                            <th>数量</th>
                            <th>定损价</th>
                            <th>核价价格</th>
                            <th>价格方案</th>
                            <th>是否回收</th>
                            <th>状态</th>
                            <th>删除操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            <tr id="tr_addParts">
                                <td colspan="11" class="text-left">
                                    <button type="button" class="btn-info btn-sm" onclick="addParts(this);">配件添加</button>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right">
                                    <label>残值:</label><input value="" name="" class="width80"/>

                                </td>
                                <td colspan="5" class="text-left">
                                    <label>残值核价:</label><input value="" name="" class="width80"/>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right">
                                    <label>小计:</label><input value="" name="" class="width80 calculateSum" />

                                </td>
                                <td colspan="5" class="text-left">
                                    <label>小计:</label><input value="" name="" class="width110" id="calculateSum1"/>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right">
                                    <label style="font-size: 6px;">指定管理费:</label><input value="" name="" class="width80"/>

                                </td>
                                <td colspan="5" class="text-left">
                                    <label style="font-size: 8px;">核价管理费:</label><input value="" name="" class="width80"/>
                                </td>
                            </tr>
                        </tbody>

                    </table>
                </div>

            </div>
            <!--定损核价明细结束-->
            <!--险种修理项目价格合计-->
            <div class="row">
                <div class="col-md-12">
                    <div class="modelTitle text-center">
                        <label>工时信息</label>
                    </div>
                    <table class="table table-bordered table-condensed" id="manHourTable">
                        <thead>
                        <tr class="tableTheadcolor">
                            <th>险种名称</th>
                            <th>修理项目</th>
                            <th>工时费报价</th>
                            <th>工时费核损</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--<tr class="tableTrcolor">
                            <td colspan="6" style="text-align: left;">喷漆项目</td>
                        </tr>-->

                        <tr id="manHourAdd">
                            <td colspan="6" class="text-left">
                                <button type="button" class="btn-info btn-sm" onclick="addItems(this);">工时添加</button>
                            </td>

                        </tr>
                       <!-- <tr class="tableTrcolor">
                            <td colspan="6" style="text-align: left;">钣金项目</td>
                        </tr>

                        <tr>
                            <td colspan="6" class="text-left">
                                <button type="button" class="btn-info btn-mini" onclick="addItems(this);">添加</button>
                            </td>
                        </tr>
                        <tr class="tableTrcolor">
                            <td colspan="6" style="text-align: left;">电工项目</td>
                        </tr>
                        <tr>
                            <td colspan="6" class="text-left">
                                <button type="button" class="btn-info btn-mini" onclick="addItems(this);">添加</button>
                            </td>
                        </tr>-->
                        <tr>
                            <td colspan="3"  style="text-align: right;"><label>小计:<input style="" value="" name="" id="calculateSumManHour1"/></label></td>
                            <td colspan="3" style="text-align: left;">小计:<label><input style="" value="" name="" id="calculateSumManHour2"/></label></td>
                        </tr>
                        </tbody>

                    </table>
                </div>
            </div>
            <!--险种修理项目价格合计结束-->
            <!--添加费用项开始-->
            <div class="row">
                <div class="col-md-12">
                    <div class="modelTitle text-center">
                        <label>费用信息</label>
                    </div>
                    <table class="table table-condensed table-bordered" id="feeTable">
                        <thead>
                        <tr class="tableTheadcolor">
                            <th>定险险种</th>
                            <th>费用类型</th>
                            <th>费用金额</th>
                            <th>核损金额</th>
                            <th>说明</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr id="tr_addCost">
                            <td  style="text-align: left;" >
                                <button type="button" class="btn-info btn-sm" onclick="addCost(this);">费用添加</button>
                            </td>

                            <td colspan="2" class="text-right">
                                <label>小计:<input value="" name="" id="calculateSumFee1"/></label>
                            </td>
                            <td colspan="3" class="text-left">
                                <label>小计:<input value="" name="" id="calculateSumFee2"/></label>
                            </td>

                        </tr>
                        <tr>
                            <td colspan="6" style="height: 20px;">
                            </td>
                        </tr>
                        <tr  rowspan="3">
                            <td colspan="6"class="text-left" >
                                <label>定损说明:(250字以内)
                                    <textarea rows="3" style="width: 780px;" name="dssm" id="dssm"></textarea>
                                </label>
                            </td>
                        </tr>
                        </tbody>

                    </table>
                </div>

            </div>
            <!--添加费用项结束-->
            <div class="row" style="margin-bottom: 20px;    ">
                <div class="col-md-12 text-center">
                    <label>
                        <button type="button" class="btn btn-mini">影像资料</button>
                        <button type="button" class="btn btn-mini" id="save"> 保存 </button>
                        <button type="button" class="btn btn-mini" id="submit" > 提交 </button>
                        <button type="button" class="btn btn-mini">关闭</button>
                        <button type="button" class="btn btn-mini">历史信息</button>
                        <button type="button" class="btn btn-mini">交管车辆查询校验</button>
                    </label>
                </div>
            </div>


        </form>

    </div>

</div>

</body>
</html>